package com.yanqu.road.server.cmd.grandchild.born;

import com.yanqu.road.entity.grandchild.GrandChildData;
import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.grandson.GrandChildModule;
import com.yanqu.road.server.pb.GrandChildPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GRANDSON_DATA_REQ,desc = "")
public class GetGrandChildDataCmd extends AbstractCommand {
    private String childId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GrandChildProto.GrandChildDataReqMsg req = GrandChildProto.GrandChildDataReqMsg.parseFrom(packet.getBytes());
        childId = req.getChildId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        GrandChildData grandChild = player.getModule(GrandChildModule.class).getGrandChild(childId);
        GrandChildProto.GrandChildDataRespMsg.Builder resp = GrandChildProto.GrandChildDataRespMsg.newBuilder();
        if (grandChild == null) {
            resp.setRet(GameErrorCode.E_GRAND_CHILD_NO_EXIST);
        }else {
            resp.setRet(0);
            GrandChildProto.GrandChildMsg.Builder childMsg = GrandChildPb.parseGrandChildMsg(grandChild);
            resp.setGrandChild(childMsg);
        }
        player.sendPacket(ClientProtocol.U_GRANDSON_DATA_REQ,resp);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
